package com.neuedu.corejava.ch14;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class CharServer3 {
	
	public void start() {
		int port = 8888;
		ServerSocket serverSocket = null;
		try {
			serverSocket = new ServerSocket(port);
			System.out.println("服务器启动成功！");	
			while(true) {
		        Socket socket = serverSocket.accept();
		        System.out.println("客户端连接成功："+socket.getInetAddress().getHostAddress()+""+socket.getPort());
		        new Thread(new Chat(socket)).start();
			}	
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			if (serverSocket!=null) {
				try {
					serverSocket.close();
				} catch (IOException e) {
				}
			}
		}


	}

	public static void main(String[] args) {
		new  CharServer3().start();

	}

}
